<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: SimpleTextPortlet.php 413 2011-01-04 21:22:15Z steen.rabol $
 *
 */

Prado::using('Application.Portlets.Portlet');
Prado::using('Application.Portlets.SimpleTextPortlet.Common.SimpleTextPortletRecord');

class SimpleTextPortlet extends Portlet
{
	public function onInit($param)
	{
		parent::onInit($param);
		$cname	= 'prop_SimpleTextPortlet_' . $this->Application->Service->RequestedPagePath . '_' . $this->Parameters['id'];

		$c = PortalConfigRecord::finder()->findByName($cname);
		if($c)
		{
			$cvalues = Prado::unserialize($c->value);
			if(is_array($cvalues) && count($cvalues) > 0)
			{
				$style = "";

				if(isset($cvalues['textcolor']))
				{
					$style .= "color:" . $cvalues['textcolor'] . ";";
				}

				if(isset($cvalues['backgroundcolor']))
				{
					$style .= "background-color:" . $cvalues['backgroundcolor'] . ";";
				}
				if(isset($cvalues['bordertype']) || isset($cvalues['bordercolor']) || isset($cvalues['bordersize']))
				{
					$bc = (isset($cvalues['bordercolor']) ? $cvalues['bordercolor'] : '#000000');
					$bt = (isset($cvalues['bordertype']) ? $cvalues['bordertype'] : 'solid');
					$bs = (isset($cvalues['bordersize']) ? TPropertyValue::ensureInteger($cvalues['bordersize']) : '1') . 'px';
					$style .= "border:$bt $bs $bc;";
				}
				$this->pnlSimpleTextContent->Style	= $style;
			}
		}
	}

	public function onLoad($p)
	{
		parent::onLoad($p);
		$stRecord	= SimpleTextPortletRecord::finder()->findByPk($this->Parameters['id']);

		if($stRecord)
		{
			$this->SimpleText->Text 				= nl2br(html_entity_decode($stRecord->content));
			$this->pnlSimpleTextContent->CssClass	= $stRecord->css;
		}
		else
		{
			$this->SimpleText->Text 	= '';
			$this->pnlSimpleTextContent->CssClass	= 'simpletextportlet';
		}
	}

	public function SearchQuery($queryvalue)
	{
		return "select tblpagecontent.pagename,tblconfig.value as text from tblpagecontent,tblconfig where tblpagecontent.id = substring(tblconfig.name,4,999) && substring(tblconfig.name,1,2) = 'st' && tblconfig.value like '%$queryvalue%'";
	}
}
?>